package com.chookss.mine.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chookss.R;
import com.chookss.base.BaseViewHolderEx;
import com.chookss.tools.GlideUtils;
import com.chookss.tools.Utils;
import com.chookss.video.VideoOnePlayActivity;
import com.chookss.video.entity.VideoEntity;
import com.johnrambo.ktea.common.klogutil.KLog;

import java.util.List;

import io.reactivex.annotations.Nullable;

public class MyMoreVideoAdapter extends BaseQuickAdapter<VideoEntity, BaseViewHolderEx> {
    private Context context;
    private int width, height;
    private String vedioType = "2";//1打开单个2跳转集合
    private int employeeCodeType;//0自己的主页1别人的主页

    public MyMoreVideoAdapter(int layoutResId, Context context, @Nullable List<VideoEntity> data, String vedioType, int employeeCodeType) {
        super(layoutResId, data);
        this.context = context;
        this.employeeCodeType = employeeCodeType;
        this.vedioType = vedioType;
        width = (Utils.getScreenWidthPixel(context) - Utils.dip2px(context, 12)) / 3;
        height = width * 290 / 232;
    }

    @Override
    protected void convert(BaseViewHolderEx helper, VideoEntity item) {
        RelativeLayout rl = helper.getView(R.id.item_rl);
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) rl.getLayoutParams();
        params.height = height;
        params.width = width;
        rl.setLayoutParams(params);
        ImageView ivBg = helper.getView(R.id.ivBg);
        ImageView ivZan = helper.getView(R.id.ivZan);
        ImageView ivStatus = helper.getView(R.id.ivStatus);
        TextView tvTitle = helper.getView(R.id.tvTitle);
        TextView tvZan = helper.getView(R.id.tvZan);
        tvTitle.setText(item.videoTitle);
        tvZan.setText(item.videoLikeCounts + "");
        GlideUtils.load(context, item.videoCoverPath, ivBg, R.drawable.default_vedios);
        if ("0".equals(item.isLike)) {
            ivZan.setBackgroundResource(R.drawable.icon_like);
        } else {
            ivZan.setBackgroundResource(R.drawable.icon_liked);
        }
        KLog.i(item.videoOpenStatus+"--"+item.videoAuditStatus+"--"+item.videoStatus);
        if ("0".equals(item.videoOpenStatus)) {
            //是否公开 0公开1私密
            if ("0".equals(item.videoAuditStatus)) {
                // 0审核中1审核通过2审核未通过
                ivStatus.setVisibility(View.VISIBLE);
                ivStatus.setBackgroundResource(R.drawable.icon_shen);
                item.isShare="0";
            } else if ("1".equals(item.videoAuditStatus)) {
                if ("1".equals(item.videoStatus)) {
                    //是否上架 0下架1上架
                    ivStatus.setVisibility(View.GONE);
                    item.isShare="1";
                } else {
                    item.isShare="0";
                    ivStatus.setVisibility(View.VISIBLE);
                    ivStatus.setBackgroundResource(R.drawable.icon_xiajia);
                }
            } else {
                item.isShare="0";
                ivStatus.setVisibility(View.VISIBLE);
                ivStatus.setBackgroundResource(R.drawable.icon_tui);
            }
        } else {
            item.isShare="0";
            ivStatus.setVisibility(View.VISIBLE);
            ivStatus.setBackgroundResource(R.drawable.icon_private);
        }
        helper.getItemView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent  intent = new Intent(context, VideoOnePlayActivity.class);

                intent.putExtra("watermark", "2");
                intent.putExtra("video", item);
                context.startActivity(intent);
            }
        });
    }

}
